#ifndef CALCULATING_H
#define CALCULATING_H

#define MAX_NUM_SIZE       30 //maximum number of entered characters and

#define GALC_SIGN_PLUS     0
#define GALC_SIGN_MINUS    1
#define GALC_SIGN_MULTIPLY 2
#define GALC_SIGN_DIVISION 3
#define GALC_SIGN_FRACTION 4

class galc //Gui cALCculator class
{
private:
    bool started = false;
    bool numberInputed = false;

    struct inputedNumbers{
        double numbers[MAX_NUM_SIZE]; //array with input numbers
        int thisNum = 0; //current free space in the array of "numbers"

        double number = 0;
        int fractionOn = 1;
        bool positive;
    };

    inputedNumbers inpNums[MAX_NUM_SIZE]; //fuck this
    int thisInputNumber = 0; //current free space in the "inpNums"

    int inputedSigns[MAX_NUM_SIZE - 1]; //fraction signs is not included
    int thisInputSign = 0;

    void endNum(){ //end of input number function (backend)
        int num = 0; // result number
        int multiplyBy = 1; // and this is like a scale in a neural network :D

        /*
         * a loop in which each element of the array is defined in the variable num,
         * from which it is passed to the final definition of the number
        */
        for(int i = 0; i <= inpNums[thisInputNumber].thisNum; i++){ //enter algoritm :D

            // a loop that determines how many times to multiply a number by 10
            for(int b = 0; b <= inpNums[thisInputNumber].thisNum - i; b++){
                multiplyBy *= 10;
            }
              num += inpNums[thisInputNumber].numbers[i] * multiplyBy;
        }
        inpNums[thisInputNumber].number = num;
        thisInputNumber++;
    }

public:
    /*
     * if the entered number in "addNumber" function does not exceed the size of the array,
     * then it returns "true", otherwise "false"
    */
    bool addNumber(double input){
        if(!numberInputed && thisInputNumber != MAX_NUM_SIZE){
            if(inpNums[thisInputNumber].thisNum < MAX_NUM_SIZE){
                inpNums[thisInputNumber].numbers[inpNums[thisInputNumber].thisNum] = input;
                inpNums[thisInputNumber].thisNum++;
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    bool endOfNumber(){ //function that completes the input of the current number
        if(!numberInputed){
            numberInputed = true;
            endNum();
            return true;
        } else {
            return false;
        }
    }

    bool addSign(int index){
        if(thisInputNumber <= MAX_NUM_SIZE){
            if(index == GALC_SIGN_FRACTION && inpNums[thisInputNumber].fractionOn != 1 && !numberInputed && !started){
                for(int i = 0; i <= inpNums[thisInputNumber].thisNum; i++){
                    inpNums[thisInputNumber].fractionOn *= 0.1;
                }
                return true;
            } else if(numberInputed){
                if(index == GALC_SIGN_PLUS){
                    inputedSigns[thisInputSign] = GALC_SIGN_PLUS;
                } else if(index == GALC_SIGN_MINUS){
                    inputedSigns[thisInputSign] = GALC_SIGN_MINUS;
                } else if(index == GALC_SIGN_MULTIPLY){
                    inputedSigns[thisInputSign] = GALC_SIGN_MULTIPLY;
                } else if(index == GALC_SIGN_DIVISION){
                    inputedSigns[thisInputSign] = GALC_SIGN_DIVISION;
                }
                numberInputed = false;
                return true;
            }
        } else {
            return false;
        }
    }

    double getResult(){
        if(started && !numberInputed){

            int indexs[MAX_NUM_SIZE]; //array with indexs with division or multiply
            int thisIndex = 0;

            for(int i = 0; i <= thisInputSign; i++){ //search for division or multiply in signs array
                if(inputedSigns[i] == GALC_SIGN_MULTIPLY || inputedSigns[i] == GALC_SIGN_DIVISION){

                    if(thisIndex == 0) thisIndex = 1;

                    indexs[thisIndex] = inputedSigns[i];
                    thisIndex++;
                }
            }

            if(thisIndex != 0)
        }
    }
};

#endif // CALCULATING_H
